package cz.fi.muni.pb138.spring2013.dtd2xsd.entities;

import cz.fi.muni.pb138.spring2013.dtd2xsd.visitor.interfaces.Visitable;
import cz.fi.muni.pb138.spring2013.dtd2xsd.visitor.interfaces.Visitor;
import java.util.Collections;
import java.util.List;

/**
 * This class represents an Attribute in DTD and XML Schema
 *
 * @author Slavomir Krupa
 */
public class Attribute implements Visitable {

    private String name;
    private String defaultValue;
    private boolean fixed;
    private boolean required;
    private AttributeType type;
    private List<String> enumeratedValues;

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(this);
    }

    public List<String> getEnumeratedValues() {
        return Collections.unmodifiableList(enumeratedValues);
    }

    public void setEnumeratedValues(List<String> enumeratedValues) {
        this.enumeratedValues = enumeratedValues;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public boolean isFixed() {
        return fixed;
    }

    public void setFixed(boolean fixed) {
        this.fixed = fixed;
    }

    public boolean isRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    public AttributeType getType() {
        return type;
    }

    public void setType(AttributeType type) {
        this.type = type;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Attribute other = (Attribute) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if ((this.defaultValue == null) ? (other.defaultValue != null) : !this.defaultValue.equals(other.defaultValue)) {
            return false;
        }
        if (this.fixed != other.fixed) {
            return false;
        }
        if (this.required != other.required) {
            return false;
        }
        if (this.type != other.type) {
            return false;
        }
        if (this.enumeratedValues != other.enumeratedValues && (this.enumeratedValues == null || !this.enumeratedValues.equals(other.enumeratedValues))) {
            return false;
        }
        return true;
    }
}
